<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>DWR Test with JavaScript (without IFrame)</title>
		<script
				src="gwt/com.eliasbalasis.dwr4gwt.test.Test/pagebus.js">
				language="JavaScript1.2"
		</script>
		<script type="text/javascript">
			if(window.parent.PageBus) {
				window.PageBus = window.parent.PageBus;
			}
		</script>

		<script type="text/javascript">
		</script>
	</head>

	<script type="text/javascript" src="dwr/engine.js"></script>
	<script type="text/javascript" src="dwr/util.js"></script>
	<script type="text/javascript" src="dwr/interface/RemoteFunctions.js"></script>

	<script type="text/javascript">
			function doSubscribe() {
				window.PageBus.subscribe(
					'com.eliasbalasis.dwr4gwt.publisher.subject',
					null,
					function(callbackSubject, callbackMessage, callbackSubscriberData) {
						window.alert("server push");
					},
					null
					);
			}
		function enableReverseAjax() {
			dwr.engine.setActiveReverseAjax(true);
		}
		function disableReverseAjax() {
			dwr.engine.setActiveReverseAjax(false);
		}
		function handleReply(data) {
			//window.alert("Type of data = "+typeof(data));
			//window.alert(data);
			//if (data instanceof Array)
			//	window.alert("Data is an Array");  
			dwr.util.setValue("demoReply", data);
		}
		function handleError(error) {
			//window.alert("Type of error = "+typeof(error));
			window.alert(error);
		}
		function sayHello() {
			var remoteClassName = "RemoteFunctions";
			var remoteMethodName = remoteClassName+".sayHello";
			var params = {};
			params.name = dwr.util.getValue("demoName");
			var remoteClass = eval(remoteClassName);
			var remoteMethod = eval(remoteMethodName);
			var callMetadata = {
				callback:handleReply,
				timeout:10000,
				errorHandler:handleError
				};
			var call = "remoteMethod(";
			var index = 0;
			for (var key in params) {
				if (index>0)
					call += ",";
    			call += "params."+String(key);
    			index += 1;
			}
			call +=
				",callMetadata);"
			eval(call);
		}
	</script>

	<body onload="doSubscribe();">
		<p>
		Name:
		<input type="text" id="demoName"/>
		<input value="Send" type="button" onclick="sayHello();"/>
		<br/>
		Reply: <span id="demoReply"></span>
		</p>
		<button type="button" onclick="enableReverseAjax();">Enable Reverse AJAX</button>
		<br/>
		<button type="button" onclick="disableReverseAjax();">Disable Reverse AJAX</button>
	</body>

</html>
